package com.faithbj.device.model.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;

/**
 * 项目名称：devices  
 * 
 * </br>类名称：InstrumentInfo 
 *  
 * </br>类描述：仪器信息及使用状态
 * 
 * </br>创建人：jrn  
 * 
 * </br>创建时间：2012-5-14 下午11:56:47 
 *  
 * </br>修改时间：2012-5-14 下午11:56:47  
 * 
 * </br>修改备注：仪器信息表  
 * 
 * @version 0.0.1  
 */
@Entity
@Table(name="device_info")
public class DeviceInfo implements Serializable
{
	private static final long serialVersionUID = 1L;

	private String id;// ID

	private Date createDate;// 创建日期

	private Date modifyDate;// 修改日期

	private Members member;
	
	// 分类代码
	private String classifyName;
	
	// 资产编号
	private String classifyId;
	
	// 资产名称
	private String propertyName;
	
	// 与该设备对应的图片路径
	private String imagePath;
	
	// 仪器状态
	private Integer useStatus;
	
	// 存放地点
	private String location;
	
	// 规格型号
	private String specificationType;
	
	// 固定资产使用部门
	private String deviceDpt;
	
	// 固定资产管理部门
	private String deviceMgrDpt;
	
	// 共享模式:1共享2：所内共享、3专用
	private String isShared;
	
	// 不共享的原因
	private String notShareReason;
	
	// 共享管理员
	private String shareAdmin;
	
	// 固定资产管理人
	private String assetsAdmin;
	
	// 固定资产使用人
	private String assetsUser;
	
	// 备注
	private String remark;
	
	// 测定指标
	private String metric;

	/**
	 * 按时间收费成本,单位是元/小时
	 * 
	 */
	private Integer timeCost;
	/**
	 * 按样品收费成本,单位是元/个
	 */
	private Integer countCost;	
	

	private Set<Reservation> reservations;// 预订列表
	
	
	/**
	 * 处理搜索添加时是""的情况，把""换成null
	 * @return
	 */
	@Transient
	public void handleBlankProperties()
	{
		if(StringUtils.isBlank(classifyName))
			classifyName=null;
		else
			classifyName=classifyName.trim();
		if(StringUtils.isBlank(propertyName))
			propertyName=null;
		else
			propertyName=propertyName.trim();
		
		if(StringUtils.isBlank(specificationType))
			specificationType=null;
		else
			specificationType=specificationType.trim();
		
		if(StringUtils.isBlank(metric))
			metric=null;
		else
			metric=metric.trim();
		
		if(StringUtils.isBlank(isShared))
			isShared=null;
	}

	@Id
	@Column(length = 32, nullable = true)
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name="create_date",insertable=true,updatable = false)
	public Date getCreateDate() {
		return createDate;
	}
	
	
	@Column(name="modify_date",insertable=true,updatable = true)
	public Date getModifyDate() {
		return modifyDate;
	}
	
	@ManyToOne(cascade = { CascadeType.PERSIST }, targetEntity = Members.class, fetch = FetchType.EAGER)  
	@JoinColumn(name = "user_name", referencedColumnName = "username") 
	public Members getMember()
	{
		return member;
	}

	@Column(name = "classify_name", nullable = false)	
	public String getClassifyName()
	{
		return classifyName;
	}

	@Column(name = "classify_id", nullable = false)	
	public String getClassifyId()
	{
		return classifyId;
	}

	@Column(name = "property_name", nullable = true)
	public String getPropertyName()
	{
		return propertyName;
	}

	@Column(name = "image_path")
	public String getImagePath()
	{
		return imagePath;
	}

	@Column(name = "use_status", nullable = true)
	public Integer getUseStatus()
	{
		return useStatus;
	}

	@Column(name = "location", nullable = true)
	public String getLocation()
	{
		return location;
	}

	@Column(name = "specification_type")
	public String getSpecificationType()
	{
		return specificationType;
	}

	@Column(name = "metric", nullable = true)
	public String getMetric()
	{
		return metric;
	}

	@Column(name = "device_dpt", nullable = true)
	public String getDeviceDpt()
	{
		return deviceDpt;
	}
	@Column(name = "device_mgrdpt", nullable = true)
	public String getDeviceMgrDpt() {
		return deviceMgrDpt;
	}
	
	@Column(name = "is_shared", nullable = false)
	public String getIsShared()
	{
		return isShared;
	}
	/**
	 * 不共享原因
	 * @return
	 */
	@Column(name = "not_share_reason")
	public String getNotShareReason()
	{
		return notShareReason;
	}

	@Column(name = "share_admin")
	public String getShareAdmin()
	{
		return shareAdmin;
	}
	
	@Column(name = "assets_admin")
	public String getAssetsAdmin() {
		return assetsAdmin;
	}
	@Column(name = "assets_user")
	public String getAssetsUser() {
		return assetsUser;
	}
	
	
	@Column(name = "remark")
	public String getRemark()
	{
		return remark;
	}
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "device")
	public Set<Reservation> getReservations() {
		return reservations;
	}

	@Column(name="count_cost")
	public Integer getCountCost() {
		return countCost;
	}

	@Column(name="time_cost")
	public Integer getTimeCost() {
		return timeCost;
	}

	public void setMember(Members member)
	{
		this.member = member;
	}

	public void setImagePath(String imagePath)
	{
		this.imagePath = imagePath;
	}
	
	public void setClassifyName(String classifyName) 
	{
		this.classifyName = classifyName;
	}
	
	public void setClassifyId(String classifyId)
	{
		this.classifyId = classifyId;
	}

	public void setPropertyName(String propertyName)
	{
		this.propertyName = propertyName;
	}

	public void setUseStatus(Integer useStatus)
	{
		this.useStatus = useStatus;
	}
	
	public void setLocation(String location)
	{
		this.location = location;
	}
	
	public void setSpecificationType(String specificationType)
	{
		this.specificationType = specificationType;
	}

	public void setDeviceDpt(String deviceDpt)
	{
		this.deviceDpt = deviceDpt;
	}

	public void setMetric(String metric)
	{
		this.metric = metric;
	}

	public void setReservations(Set<Reservation> reservations)
	{
		this.reservations = reservations;
	}

	public void setIsShared(String isShared)
	{
		this.isShared = isShared;
	}

	public void setNotShareReason(String notShareReason)
	{
		this.notShareReason = notShareReason;
	}
	
	public void setShareAdmin(String shareAdmin)
	{
		this.shareAdmin = shareAdmin;
	}

	public void setRemark(String remark)
	{
		this.remark = remark;
	}

	public void setAssetsAdmin(String assetsAdmin) {
		this.assetsAdmin = assetsAdmin;
	}


	public void setAssetsUser(String assetsUser) {
		this.assetsUser = assetsUser;
	}

	public void setDeviceMgrDpt(String deviceMgrDpt) {
		this.deviceMgrDpt = deviceMgrDpt;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}
	
	public void setCountCost(Integer countCost) {
		this.countCost = countCost;
	}
	public void setTimeCost(Integer timeCost) {
		this.timeCost = timeCost;
	}

	/**
	 * 显示用的原图路径
	 * @return
	 */
	@Transient
	public String getImageView()
	{
		if(StringUtils.isNotBlank(imagePath))
		{
			String filename=StringUtils.substringAfterLast(imagePath, "/");
			return filename;
		}
	    return null;
	}
	
}
